<template>
  <div class="page">
    <div class="c_info">
      <img class="c_pic" :src="img" mode="widthFix">
      <div>{{name}}</div>
    </div>
     <!-- href="/pages/customerorderdetail/main" -->
    <div class="weui-cells consumelist" v-if="resultList.length">
      <a class="weui-cell weui-cell_access" v-for="(item,index) in resultList" :key="index" @click="goDetail(item)">
        <div class="weui-cell__bd">订单号：{{item.id}}</div>
        <div class="weui-cell__hd c_date">{{item.createTime}}</div>
        <div class="weui-cell__ft">查看详细</div>
      </a>

    </div>
    <div class="outData" v-else>
      <p style="display:flex;justify-content: center;width: 100%">暂无数据</p>
       </div>

  </div>
</template>

<script>
import card from '@/components/card'
 import * as appId from "@/utils/util"
 import {getTIme} from "@/utils/util"
export default {
  data () {
    return {
      current: 0,
      phone:"",
      userId:"",
      pageNo:1,
      pageSize:10,
      resultList:[],
      result:[],
      phone:"",
      img:"",
      name:"",
      cardId:""
    }
  },
  onShow(){
    wx.setNavigationBarTitle({
      title: "顾客订单"
    })
    this.userInfo =wx.getStorageSync('userInfo')&&JSON.parse(wx.getStorageSync('userInfo'))
    if(this.userInfo) {

      this.userId=this.userInfo.baseUserId;
      this. getDetail()



    }else{
      wx.showToast({
        title:'请先登录',
        icon: 'none',
        duration: 2000
      })
    }
  },
  components: {
    card
  },
  onLoad(option){
    this.phone=option.phone;
    this.img=option.img;
    this.name=option.name;
    this.cardId=option.cardId;
  },
  methods: {
    goDetail(item){
      let url=`/pages/customerorderdetail/main?id=${item.productInfo[0].productId}&ordId=${item.id}`
       wx.navigateTo({ url })
    },
    getDetail(){
      let that=this;
      this.$http.request({
                method:"post",
                url:"/v1.0/appletLogin/customerOrderList",
                body:{
      					  "appid":appId.appId,
      					  	"phone":this.phone,
      					  	"pageNo":this.pageNo,
      					  	"pageSize":this.pageSize,
      					  	"userId":this.userId,
                  "status":"all",
                  cardId:this.cardId
      				   }
      }).then((data)=>{
        if(data.code==0){
          that.result=data.result;
           if (that.pageNo > 1) {
          that.resultList.push(...data.result)
            console.log(that.resultList)
          }else{
            that.resultList=data.result;
          }
          that.resultList.forEach((a,i)=>{
            a.createTime=getTIme(a.orderTime)
          })
           if(!data.length){
           wx.stopPullDownRefresh();
        //    wx.showToast({
        //   title: '暂无更多数据',
        //   icon: 'none',
        //   duration: 2000
        // })
        }

        }else{
           wx.showToast({
          title: `${data.message}`,
          icon: 'none',
          duration: 2000
        })
        }
      })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.c_info{
  background: #fff;
  padding: 0.8em 0;
  text-align: center;
  font-size: 0.8em;
}
.c_pic{
  width: 4.4em;
  height: 4.4em;
  border-radius: 50%;
  margin: 0 auto;
}
.consumelist{
  font-size: 0.7em;
}
.c_date{
  color: #999;
  padding-right: 0.6em;
}
</style>
